< previous page page_151 next page >

Page 151
0151-01.jpg
Figure 5.3
Example program ObjPrint displays a
rectangle on its form or on the Printer object.
Subroutine mnuFilePrint_Click is invoked when you select Print from the program's File menu. That procedure uses DrawPicture to display the diamond on the printer. It then calls the printer's EndDoc method to finish printing the document.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw a diamond on the form or printer.
Private Sub DrawPicture(obj As Object)
    obj.CurrentX = 1540
    obj.CurrentY = 100
    obj.Line -Step(1440, 1440)
    obj.Line -Step(-1440, 1440)
    obj.Line -Step(-1440, -1440)
    obj.Line -Step(1440, -1440)
End Sub

' Draw the picture on the form.
Private Sub Form_Paint()
    Cls
    DrawPicture Me
End Sub

' Draw the picture on the Printer object.
Private Sub mnuFilePrint_Click()
    MousePointer = vbHourglass
    DoEvents

    DrawPicture Printer
    Printer.EndDoc

    MousePointer = vbDefault
End Sub
Displaying a print preview at multiple scales is only slightly harder. Use the previous methods to generate a preview image in a picture box with Visible property set to False.

 
< previous page page_151 next page >